// 1. 声明Person构造函数
function Person() {}
Person.prototype.head = 1
Person.prototype.foot = 2
Person.prototype.show = function () {
  console.log(`{name:${this.name},no:${this.no},foot:${this.foot},head:${this.head}}`)
}
// 2. 声明Student构造函数
function Student(name, no) {
  this.name = name
  this.no = no
}
// // 3. 创建空对象
// function F() {}
// F.prototype = Person.prototype
// F.prototype.constructor = F
// const f = new F()
// // 4. 实现原型链继承
// Student.prototype = f
// // 5. 避免构造函数紊乱，重置构造函数
// Student.prototype.constructor = Student

// 封装一个继承函数
function extend(Child, Parent) {
  function F() {}
  F.prototype = Parent.prototype
  F.prototype.constructor = F
  let f = new F()
  Child.prototype = f
  Child.prototype.constructor = Child
  return f
}
let f = extend(Student, Person)

// 6. 创建实例对象
let stu = new Student('Tom', 1)

// 7. 修改stu的原型对象的属性和方法，不会影响Person的原型对象的属性和方法
console.log('-------------stu-------------')
let st = new Student('Sam', 2)
st.__proto__.foot = 4
stu.show()
console.log('--------------f------------')
console.log(f)
console.log('--------------p------------')
let p = new Person()
p.show()
